package com.hualan.controller;

import com.hualan.pojo.ConsultBooking;
import com.hualan.pojo.Result;
import com.hualan.service.ConsultBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hdx")
public class ConsultBookController {
    @Autowired
    private ConsultBookService consultBookService;
    @GetMapping
    public Result consultBooking(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "3") Integer pageSize,
            String consultType){
        return Result.success(consultBookService.findConsultBooking(pageNum,pageSize,consultType));
    }

    @DeleteMapping({"/{id}"})
    public Result deleteByKey(@PathVariable Long id){
        int i = consultBookService.deleteByKey(id);
        if(i !=0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @PostMapping
    public Result insert(@RequestBody ConsultBooking record){
        int insert = consultBookService.insert(record);
        if(insert != 0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }

    @DeleteMapping("/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        int i = consultBookService.deleteBatch(ids);
        if (i != 0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }
}
